package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Tickets;
import com.ruoyi.system.service.ITicketsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 票务信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-30
 */
@Controller
@RequestMapping("/system/tickets")
public class TicketsController extends BaseController
{
    private String prefix = "system/tickets";

    @Autowired
    private ITicketsService ticketsService;

    @RequiresPermissions("system:tickets:view")
    @GetMapping()
    public String tickets()
    {
        return prefix + "/tickets";
    }

    /**
     * 查询票务信息列表
     */
    @RequiresPermissions("system:tickets:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Tickets tickets)
    {
        startPage();
        List<Tickets> list = ticketsService.selectTicketsList(tickets);
        return getDataTable(list);
    }

    /**
     * 导出票务信息列表
     */
    @RequiresPermissions("system:tickets:export")
    @Log(title = "票务信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Tickets tickets)
    {
        List<Tickets> list = ticketsService.selectTicketsList(tickets);
        ExcelUtil<Tickets> util = new ExcelUtil<Tickets>(Tickets.class);
        return util.exportExcel(list, "票务信息数据");
    }

    /**
     * 新增票务信息
     */
    @RequiresPermissions("system:tickets:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存票务信息
     */
    @RequiresPermissions("system:tickets:add")
    @Log(title = "票务信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Tickets tickets)
    {
        return toAjax(ticketsService.insertTickets(tickets));
    }

    /**
     * 修改票务信息
     */
    @RequiresPermissions("system:tickets:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Tickets tickets = ticketsService.selectTicketsById(id);
        mmap.put("tickets", tickets);
        return prefix + "/edit";
    }

    /**
     * 修改保存票务信息
     */
    @RequiresPermissions("system:tickets:edit")
    @Log(title = "票务信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Tickets tickets)
    {
        return toAjax(ticketsService.updateTickets(tickets));
    }

    /**
     * 删除票务信息
     */
    @RequiresPermissions("system:tickets:remove")
    @Log(title = "票务信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ticketsService.deleteTicketsByIds(ids));
    }
}
